/**
 * Copyright 2011 Honeywell Federal Manufacturing & Technologies, LLC. This material was produced under U.S. Government
 * contract DE-ACO4-01AL66850, Honeywell Federal Manufacturing & Technologies, LLC, (FM&T) with the U. S. Department of
 * Energy for the operation of the Kansas City Plant . The U.S. Government has rights to use, reproduce, and distribute
 * this software.  NEITHER THE GOVERNMENT NOR Honeywell Federal Manufacturing & Technologies, LLC, MAKES ANY WARRANTY,
 * EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE.  If software is modified to produce
 * derivative works, such modified software should be clearly marked, so as not to confuse it with the version available
 * from FM&T.
 *
 * Additionally, this program is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License Version 3 published by the Free Software Foundation. Accordingly, this program is distributed in
 * the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this library.
 * If not, see http://www.gnu.org/licenses/.
 */
package org.braintrain.services.dao;

import com.kcp.ko.fmtnmlib.service.dao.HibernatePersistenceDAO;
import org.braintrain.domain.Module;
import org.braintrain.domain.Navigation;

import java.util.List;

/**
 * The Navigation DAO Interface.  This Interface outlines the various methods used
 * when dealing with Navigation.
 * 
 * @author John Ericksen
 *
 */

public interface NavigationDAO extends HibernatePersistenceDAO{

    
    /**
     * 
     * Inserts a given navigation between the "current" Navigation and
     * the current.getDeltaNext() navigation
     *
     * @param current
     * @param nav
     * @return
     */
    Navigation insertNavigationPrev(Navigation current, Navigation nav);
    
    /**
     * Inserts a given navigation between the "current" Navigation and
     * the current.getDeltaPrev() navigation.
     * 
     * @param current
     * @param nav
     * @return
     */
    Navigation insertNavigationNext(Navigation current, Navigation nav);

    /**
     * Returns a list of the Main Navigation chain of a given module.  If delta is true,
     * and there exists a getDeltaNext() (See walkChainAndPopulateList()) then that chain is followed
     * instead of the getNext() path.  Also, if include deletes is true, deleted items are added to the
     * list in the appropriate places.
     * 
     * @param module
     * @param delta
     * @param includeDeletes
     * @return
     */
    List<Navigation> getMainNavigationChain(Module module, boolean delta, boolean includeDeletes);
    
    /**
     * Returns a List of Lists of Navigations that represents all the Linked navigation
     * chains for a given module.  This method acts like the getMainNavigationChain but builds up a list
     * of the 'link' chains.
     * 
     * @param module
     * @return
     */
    List<List<Navigation>> getLinkNavigationChains(Module module, boolean delta, boolean includeDeletes);

    /**
     * A simple swap function.  this function swaps the current item with the deltaNext item in the chain (if it exists).
     * EX: (1 -> 2 -> 3 -> 4) -->> (1 -> 3 -> 2 -> 4)
     * @param current
     */
    void swapWithNext(Navigation current);
    
    /**
     * A more robust swap method.  This method does not assume that the current and destination are in any
     * relation to one another (next-to or separated by 1 or more).
     * 
     * Ex:(1 -> <- 2 -> <- 3)   (4 -> <- 5 -> <- 6) -->> (1 -> <- 5 -> <- 3)   (4 -> <- 2 -> <- 6) 
     * @param current
     * @param dest
     */
    void swap(Navigation current, Navigation dest);
    
    /**
     * The core of the release() method.  Saves the delta navigation chain into place and
     * swaps in the delta content.  Also, numbers the pages.
     * @param module
     */
    void saveDeltaNavigationChanges(Module module);

    /**
     * 
     * Resets the links around a given navigation (the delta next/previous links).
     * @param nav
     */
    void removeDeltaNavigationFromChain(Navigation nav);

    /**
     * Removes all pending deltas from the given module.  Also, deletes
     * any delta content.  In effect, returns the given module to what is currently released
     * @param module
     */
    void saveSyncDeltaWithReleased(Module module);

    //public void convert();

}
